﻿#include <libcomm.h>

void __SignalHandler(int signo) 
{
	printf("SIGNAL(%d) interrupt !\n",signo);
	printf("%s",StackTracer::TraceStack().get());
	exit(0);
}


int main(int argc, char *argv[])
{
#ifndef COMM_MSVC
	struct sigaction act;
	act.sa_handler = __SignalHandler;
	MYLIB_ASSERT_ERRNO(0==sigfillset(&act.sa_mask));//forbid all signal while handler.
	act.sa_flags = 0;
	//MYLIB_ASSERT_ERRNO(0==sigaction(SIGINT,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGSEGV,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGILL,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGFPE,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGTERM,&act,NULL));
	MYLIB_ASSERT_ERRNO(0==sigaction(SIGABRT,&act,NULL));
	//signal(SIGUSR1,SIG_IGN);
#endif

	LOGDEBUG("COMLIB: %s",common_version());

	stdlist<int> lst;
	for (int i=0;i<5;i++)
	{
		lst.push_back(i);
	}

	for (int n=0;n<2;n++)
	{
		foreach(int, i, lst)
		{
			printf("%d\t", i);
		}
		printf("\n%d-------------------\n",n);

		if(n == 0)
			lst.reverse();
	}

	if (lst.size() > 0)
	{
		stdlist<int>::iterator itor = lst.end();
		itor--;
		while (itor != lst.begin())
		{
			printf("%d\t", *itor);
			itor--;
		}
		printf("%d\t", *itor);
	}
	
	
	
	getchar();
	return 0;
}